package com.shdaily.android;

import java.util.ArrayList;
import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.app.Activity;
import android.widget.*;
import android.widget.ListView;
import android.database.Cursor;
import android.widget.AdapterView.OnItemClickListener;
import android.content.Context;

public class TopNewsActivity extends ListActivity {
	
	private ArrayList<Article> articles;
	private Cursor mCursor;
	private EngineDB db;
	private Context ctx = getApplicationContext();
	
	@Override     
	protected void onCreate(Bundle savedInstanceState){         
		super.onCreate(savedInstanceState);   
		db = new EngineDB(ctx);
		setContentView(R.layout.topnewslist);  
		ListView list = (ListView) findViewById(R.id.TopNewsListView);
        list.setClickable(true);
        
        final List<Article> articleList = new ArrayList<Article>();
        ListAdapter adapter = new TopNewsAdapter(this); 
        ctx = this.getApplicationContext();
        list.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View view, int position, long index) {
            	Article article = articleList.get(position);
            	Bundle bundle = new Bundle();
            	bundle.putString("id", article.getId()+"");
            	bundle.putString("title", article.getTitle());
            	bundle.putString("summary", article.getSummary());
            	bundle.putString("author", article.getAuthor());
            	bundle.putString("hasPic", article.getHasPic()+"");
            	bundle.putString("date", article.getDate());
            	bundle.putString("body", article.getBody());

            	Intent newIntent = new Intent(ctx, ArticleActivity.class);
            	newIntent.putExtras(bundle);
            	startActivity(newIntent);

            }
        });
       
		//mCursor = this.getContentResolver().query(People.CONTENT_URI, null, null, null, null);         
		//startManagingCursor(mCursor);         // Now create a new list adapter bound to the cursor.         
		// SimpleListAdapter is designed for binding to a Cursor.         
		       
		setListAdapter(adapter);     
		//((TopNewsAdapter)adapter).refresh();
	
	}

}
